package com.hwangjr.rxbus.thread;

import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * ThreadHandler
 */
public interface ThreadHandler {
    /**
     * ThreadHandler
     */
    ThreadHandler DEFAULT = new ThreadHandler() {
        private Executor executor;
        private EventHandler handler;

        @Override
        public Executor getExecutor() {
            if (executor == null) {
                executor = Executors.newCachedThreadPool();
            }
            return executor;
        }

        @Override
        public EventHandler getHandler() {
            if (handler == null) {
                handler = new EventHandler(EventRunner.getMainEventRunner());
            }
            return handler;
        }
    };

    /**
     * getExecutor
     *
     * @return Executor
     */
    Executor getExecutor();

    /**
     * getHandler
     *
     * @return Executor
     */
    EventHandler getHandler();
}